package com.ningkang.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningkang.common.domain.ums.UserVo;
import com.ningkang.ums.domain.UserEntity;
import com.ningkang.ums.mapper.UserMapper;
import com.ningkang.ums.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @ClassName UserServiceImpl
 * @Description 用户信息接口实现类
 * @Author guoxin
 * @Date 2024/10/17 20:09
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserService{
    /**
     * 根据名称查询 用户是否存在
     * @param username
     * @return
     */
    @Override
    public UserVo selectName(String username) {
        UserEntity userEntity = this.getOne(new QueryWrapper<UserEntity>().lambda().eq(UserEntity::getUsername, username));
        if (userEntity == null){
            throw new RuntimeException("用户名不存在");
        }
        UserVo userVo = new UserVo();
        BeanUtils.copyProperties(userEntity,userVo);
        return userVo;
    }
}
